<template>
  <view class="order-details flex-column" :style="orderDetailsH5">
    <QcscrollUni
      ref="mescrollRef"
      :getData="getData"
      :top="topScroll"
      :bottom="bottomScroll"
      :height="heightScroll">
      <view class="details-item" v-for="(item, index) in ticketOrder.list" :key="index">
        <view class="title-check">
          <view class="title text-bold">
            {{ item.ticketType === 0 ? '增值税普通发票' : '增值税专用发票' }}
          </view>
          <view class="status">
            <view class="status-solid"></view>
            <text v-if="item.status === 0">待开票</text>
            <text v-if="item.status === 1">已驳回</text>
            <text v-if="item.status === 2">已开票</text>
            <text v-if="item.status === 3">开票中</text>
          </view>
        </view>
        <view class="company-name">{{ item.companyName }}</view>
        <view class="info">
          <view class="left">
            <view class="test">税号</view>
            <view class="test">申请时间</view>
            <view class="test" v-if="item.status === 1">驳回原因</view>
            <view class="test" v-if="appType == 'lznt' && item.picUrl">获取发票</view>
            <view class="test">合计</view>
          </view>
          <view class="right">
            <view class="test">
              {{ item.taxNumber ? `${item.taxNumber}` : '--' }}
            </view>
            <view class="test">
              {{ item.createTime ? `${item.createTime}` : '--' }}
            </view>
            <view class="test" v-if="item.status === 1">
              {{ item.reason ? `${item.reason}` : '--' }}
            </view>
            <view class="test" @tap="tapImage(item.picUrl)" v-if="appType == 'lznt' && item.picUrl">
              <view class="btn1">下载发票</view>
            </view>
            <view class="test">
              {{ item.totalAmount ? `￥${item.totalAmount}` : '--' }}
            </view>
          </view>
        </view>
      </view>
    </QcscrollUni>
  </view>
</template>

<script lang="ts" setup>
import { reactive } from 'vue';
import QcscrollUni from '@/components/qcscroll/qcscrollUni.vue';
import { pagingTicketRecordHistory } from '@/service/apis/mine';
import { getSystemInfo, getwv } from '@mixins/info';

const appType = import.meta.env.VITE_VUE_APP_TYPE;
console.log(appType);

const $toast: any = inject('$Toast');

const topScroll = '114rpx';
const bottomScroll = '60rpx';
let heightScroll = ref(`${getSystemInfo().screenHeight - getwv(160)}px`);

const orderDetailsH5 = computed(() => {
  // #ifdef H5
  return `height: calc(100vh - ${getSystemInfo().navHeight}px - ${getwv(53)}px)`;
  // #endif
  return '';
});
let ticketOrder = reactive({
  list: [] as Array<any>,
});
const getData = (extraParams: { pageNum: number; pageSize: number }) => {
  return new Promise(resolve => {
    pagingTicketRecordHistory({}, extraParams)
      .then((res: any) => {
        if (extraParams.pageNum === 1) {
          ticketOrder.list = res.dataList;
        } else {
          ticketOrder.list = [...ticketOrder.list, ...res.dataList];
        }
        resolve({ list: ticketOrder.list, total: res.totalCount });
      })
      .catch(() => {
        resolve({ list: [], total: 0 });
      });
  });
};

// 下载图片
const tapImage = (imgUrl: any) => {
  const imgUrlArr = [];
  imgUrlArr.push(imgUrl);
  uni.previewImage({
    urls: imgUrlArr,
    indicator: 'number',
    loop: true,
  });
};
</script>

<style lang="scss" scoped>
// #ifdef H5
:deep(#u-a-p) {
  & > div > div {
    top: 44px !important;
  }
}
// #endif
.order-details {
  position: relative;
  width: 100vw;
  height: 100vh;
  background-color: #f2f2f2;
  // #ifdef H5
  box-sizing: border-box;
  padding-top: 10px;
  // #endif

  .icon-select1 {
    color: $uni-color-primary;
    font-size: 20px;
  }

  .unselect {
    width: 20px;
    height: 20px;
    border: 1px solid $uni-color-primary;
    border-radius: 50%;
    box-sizing: border-box;
  }

  .details-item {
    margin: 0 12px;
    padding: 16px;
    background-color: #fff;
    font-size: 14px;
    color: #545454;
    border-bottom: 1px dashed #d5d5d5;
    border-radius: 8px;

    .title-check {
      display: flex;
      justify-content: space-between;
      padding-bottom: 10px;
      border-bottom: 1px solid #f2f2f2;

      .status {
        display: flex;
        align-items: center;

        .status-solid {
          width: 5px;
          height: 5px;
          border-radius: 5px;
          background-color: $uni-color-primary;
          margin-right: 6px;
        }
      }
    }

    &:last-child {
      border: 0;
    }

    .company-name {
      font-size: 16px;
      font-weight: 500;
      color: #545454;
      padding: 8px 0 4px 0;
    }

    .title {
      line-height: 24px;
      color: #000;
    }

    .info {
      display: flex;

      .left {
        width: 40%;
      }

      .right {
        width: 60%;
        text-align: right;

        .test {
          overflow: hidden; //超出的文本隐藏
          text-overflow: ellipsis; //溢出用省略号显示
          white-space: nowrap; // 默认不换行；
        }
      }

      .test {
        margin-top: 8px;
      }

      .btn1 {
        float: right;
        width: 80px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 12px;
        color: #fff;
        background-color: $uni-color-primary;
        padding: 4px 0;
        border-radius: 10px;
      }
    }
  }

  .bottom-wrap {
    position: fixed;
    display: flex;
    width: 100vw;
    bottom: 0;
    background-color: #fff;

    .money-wrap {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    .select-wrap {
      // position: absolute;
      display: flex;
      height: 100%;
      right: 8px;

      .icon-select1 {
        color: $uni-color-primary;
        font-size: 20px;
      }

      .unselect {
        width: 20px;
        height: 20px;
        border: 1px solid $uni-color-primary;
        border-radius: 50%;
        box-sizing: border-box;
      }
    }

    .left {
      flex: 1;
      height: 44px;
      margin: 9px 16px;
      color: #000;
      font-weight: 14px;

      .money-wrap {
        line-height: 44px;
        margin-bottom: 4px;
      }

      .money {
        line-height: 24px;
        margin-left: 8px;
        font-size: 20px;
      }

      .discount {
        line-height: 18px;
        font-size: 14px;
        color: $uni-color-primary;
      }
    }

    .right {
      flex: 1;
      margin: 9px 0 9px 16px;

      .bnt-pay {
        width: 136px;
        height: 44px;
        border-radius: 50px;
      }
    }
  }

  .bottom {
    width: 100%;
    height: 96px;
    position: absolute;
    bottom: 36px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    border-top: 1px solid #f1f2f3;
  }
}
</style>